import type { App } from 'vue'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// 全局注册element-plus图标
export function registerIcons(app: App) {
  for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }
}

/**
 * @usage 生成icons, 用于 unocss safelist，以支持页面动态渲染自定义图标
 */
export function getSvgIcons() {
  const feFiles = import.meta.glob('@/assets/icons/feather/*.svg', { eager: true, })
  let svgNameArray: any[] = []
  for (const [key, _value] of Object.entries(feFiles)) {
    // console.log('key', key);
    const svgName = key.replace(/^\/src.*\/(.*)\.svg/, '$1');
    // console.log('name', name);
    svgNameArray.push(svgName)
  }
  return svgNameArray
}

// const PLUGIN_ICONS_ID = 'isme:icons'
// export function pluginIcons() {
//   return {
//     name: 'isme:icons',
//     resolveId(id: any) {
//       if (id === PLUGIN_ICONS_ID)
//         return `\0${PLUGIN_ICONS_ID}`
//     },
//     load(id: any) {
//       if (id === `\0${PLUGIN_ICONS_ID}`) {
//         return `export default ${JSON.stringify(getIcons())}`
//       }
//     },
//   }
// }